<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="__STATIC__/lib/html5shiv.js"></script>
<script type="text/javascript" src="__STATIC__/lib/respond.min.js"></script>

<![endif]-->
<link rel="stylesheet" type="text/css" href="__STATIC__/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="__STATIC__/h-ui.admin/css/style.css" />
<!-- 111111 -->
<!-- <link rel="stylesheet" type="text/css" href="__STATIC__/h-ui.admin/skin/default/skin.css" id="skin" /> -->
<!--[if IE 6]>
<script type="text/javascript" src="__STATIC__/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加产品分类列表</title>
</head>
<body>
<div class="page-container">
	
<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a class="btn btn-primary radius" onclick="product_add('添加产品分类','{:url(\'index/Type/product_type_add\')}')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加产品分类</a></span></div>
<div class="mt-20">

<form action="product_category_add" method="post">

	<table class="table table-border table-bordered table-bg table-hover table-sort">
				<thead>
					<tr class="text-c">
						<th width="40"><input name="" type="checkbox" value=""></th>
						<!-- <th width="40">ID</th> -->
						<th width="60">分类名称</th>
						<th width="100">是否显示在导航栏</th>
						<th width="100">是否显示</th>
						<th width="100">操作</th>
					</tr>
				</thead>
				<?php foreach ($data as $key => $v): ?>
				 <tbody>
					<tr class="text-c va-m" where="{$v.type_id}" type_id="{$v.type_id}" type_pid="{$v.type_pid}">
						<td><input name="" type="checkbox" value=""></td>
						<!-- <td><?php echo $v['type_id'] ?></td> -->
						<td class="text-l"><a style="text-decoration:none" href="javascript:;" >
						<?php echo str_repeat("&nbsp;", $v['level']) ?>
						<img src="../../../../public/static/image/menu_minus.gif" id="icon_1" height="10" width="10" alt="" onclick="picture({$v.type_id})">&nbsp;&nbsp;&nbsp;&nbsp;<span id="type_name"><?php echo $v['type_name'] ?></span><input type="text" id="input" style="display:none" one="{$v.type_name}"></a></td>
						<!-- 是否显示导航栏 -->
						<td class="td-status">
						<?php if ($v['is_nav'] == 0){ ?>
								<span class="label label-success radius status" name="is_nav" value="1" where="<?php echo $v['type_id'] ?>">已显示</span>
						<?php } ?>
						<?php else{ ?>
							<span class="label label-success radius status" name="is_nav" value="0" where="<?php echo $v['type_id'] ?>">未显示</span>
						<?php } ?>
						</td>
						<!-- 是否显示 -->
						<td class="td-status">
						<?php if ($v['is_show'] == 0){ ?>
								<span class="label label-success radius status_show" name="is_show" value="1" where="<?php echo $v['type_id'] ?>">已显示</span>
						<?php } ?>
						<?php else{ ?>
							<span class="label label-success radius status_show" name="is_show" value="0" where="<?php echo $v['type_id'] ?>">未显示</span>
						<?php } ?>
						</td>

						<td class="td-manage"><a style="text-decoration:none" class="ml-5" onClick="product_del(this,{$v.type_id})" href="javascript:;" title="删除" where="{$v.type_id}"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
					</tr>
				</tbody>
				<?php endforeach ?>	
			</table>
		</form>
			
		</div>
</div>
</body>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="__STATIC__/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__STATIC__/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="__STATIC__/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__STATIC__/lib/laypage/1.2/laypage.js"></script>

<script type="text/javascript">


// 1111111111
$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":true,"aTargets":[0,4]}// 制定列不参与排序
	]
});


//产品分类折叠显示
function picture(type_id){
	var tr = $('[type_pid='+type_id+']');
	tr.toggle();

	$.each(tr,function(){
		var type_id = $(this).attr("type_id");

		picture(type_id);
	})
}
	


//产品分类【未显示】状态
$(document).on("click",".status",function(){
	var is_nav = $(this).attr("value");
	var type_id = $(this).attr("where");

	var _this = $(this);
	$.ajax({
		url:"{:url('index/type/product_type_status')}",
		type:"post",
		dataType:"json",
		data:{is_nav:is_nav,type_id:type_id},
		success:function(res){
			console.log(res);
			if(res == '0'){
				_this.empty();
				_this.text("已显示");
				_this.attr("value",1);
				alert(_this.text());
			}else{
				_this.empty();
				_this.text("未显示");
				_this.attr("value",0);
				alert(_this.text());
			}
		}
	})
})
//产品分类【已显示】状态
$(document).on("click",".status_show",function(){
	var is_show = $(this).attr("value");
	var type_id = $(this).attr("where");

	var _this = $(this);
	$.ajax({
		url:"{:url('index/type/product_type_status_show')}",
		type:"post",
		dataType:"json",
		data:{is_show:is_show,type_id:type_id},
		success:function(res){
			console.log(res);
			if(res == '0'){
				_this.empty();
				_this.text("已显示");
				_this.attr("value",1);
				alert(_this.text());
			}else{
				_this.empty();
				_this.text("未显示");
				_this.attr("value",0);
				alert(_this.text());
			}
		}
	})
	
})
//产品分类即点即改 
$(document).on("click","#type_name",function(){
	$(this).hide();
	var type_name = $(this).html();
	$(this).next().val(type_name);
	$(this).next().show();
	$(this).next().focus();
})
//产品分类即点即改 失焦
$(document).on("blur","#input",function(){
	var type_id = $(this).parents("tr").attr("where");
	var one = $(this).attr("one");
	var type_name = $(this).val();
	// alert(type_id)
	_this = $(this);
	$.ajax({
		url:"{:url('index/type/product_type_edit')}",
		dataType:"json",
		type:"post",
		data:{type_id:type_id,one:one,type_name:type_name},
		success:function(res){	
			if(res == 0){
				$(_this).hide();
				var type_name = $(_this).val();
	            $(_this).prev().html(type_name);
	            $(_this).prev().show();
	            alert("修改成功")
			}else{
	            $(_this).hide();
	            var type_name = $(_this).val();
	            $(_this).prev().html(type_name);
	            $(_this).prev().show();
	        }
		}
	})
})


/*产品分类-ajax删除*/
function product_del(obj,type_id){
	layer.confirm('确认要删除吗？',function(index){

		$.ajax({
			type: 'post',
			url: "{:url('index/type/product_type_del')}",      
			data:{type_id:type_id},
			dataType: 'json',
			success: function(data){
				if(data == 0){
					$(obj).parents("tr").remove();
					layer.msg('删除成功!',{icon:1,time:1000});
				}else if(data == 1){
					console.log(data.msg);
					// $(obj).parents("tr").remove();
					layer.msg('删除失败!',{icon:2,time:1000});
				
				}else{
						// console.log(data.msg);
					// $(obj).parents("tr").remove();
					layer.msg('有子集!',{icon:2,time:1000});
				}			
			}
		})		
	})
}


// /*产品分类-添加*/   模板
function product_add(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}


</script>
</body>
</html>